// https://www.acwing.com/problem/content/838/

#include <iostream>
#include <vector>

using namespace std;

const int MAX_ARRAY_SIZE = 1e5+5;

// 存储每个节点的父节点
int parents[MAX_ARRAY_SIZE];

void init(int n) {
    // 初始时，每个元素的父节点是自己
    for (int i=1; i<=n; i++) {
        parents[i] = i;
    }
}


int find(int x) {
    if (parents[x] != x) {
        parents[x] = find(parents[x]);
    }
    return parents[x];
}

void unite(int node1, int node2) {
    parents[find(node1)] = find(node2);
}

// 判断两个元素是否属于同一集合
bool connected(int x, int y) {
    return find(x) == find(y);
}

int main() {
    int m, n;
    char ch;
    int node1, node2;
    cin>>m>>n;
    init(n);
    while (n-->0) {
        cin>>ch>>node1>>node2;
        if (ch == 'M') {
            unite(node1, node2);
        } else if (ch == 'Q') {
            auto result = connected(node1, node2);
            result ? cout<<"Yes"<<endl: cout<<"No"<<endl;
        }
    }
    return 0;
}
